/******************************************************************************
//             INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//        Copyright (c) 2000-2001 Intel Corporation. All Rights Reserved.
//
//  Description:
//      Intel(R) JPEG library for X platform 
//
********************************************************************************/
#include "_ijx.h"

#if IPPJPVER!=1
/******************************************************************************
// Name:            ijGetHuffmanFREQ_Gray_DC
// Description:     Get Huffman Frequency for progressive mode
// Input Arguments:
//              ah: Indicates approximation high
//              al: Indicates approximation low
//          ppFreq: Points to the frequency buffer array.
//    pEncodeState: Identifies IJENCODESTATE strcuture.
// Output Arguments:
//        ppMCUBuf: Identifies MCU coefficients buffer.
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_INSUFFICIENTBUF
//                  IJX_RTCODE_ERRPARSE
//                  
******************************************************************************/
IJXRESULT ijGetHuffmanFREQ_Gray_DC(const Ipp16s **ppMCUBuf, 
                                 int **ppFreq,
                                 int ah,
                                 int al,
                                 IJENCODESTATE *pEncodeState)
{
    if (0!=ah) {
        return IJX_RTCODE_OK;
    }

    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[0],
                                        ppFreq[0],
                                        &(pEncodeState->dcPred[0]),
                                        al);

//    pEncodeState->counter.nScanMCUCounter++;

    if ( (0<pEncodeState->nRstInterval) ){
        pEncodeState->counter.nDRICounter--;
        if (0==pEncodeState->counter.nDRICounter) {
            pEncodeState->counter.nDRICounter=pEncodeState->nRstInterval;
            pEncodeState->dcPred[0]=0;
        }
    }

    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijGetHuffmanFREQ_444_DC
// Description:     Get Huffman Frequency for progressive mode
// Input Arguments:
//              ah: Indicates approximation high
//              al: Indicates approximation low
//          ppFreq: Points to the frequency buffer array.
//    pEncodeState: Identifies IJENCODESTATE strcuture.
// Output Arguments:
//        ppMCUBuf: Identifies MCU coefficients buffer.
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_INSUFFICIENTBUF
//                  IJX_RTCODE_ERRPARSE
//                     
******************************************************************************/
IJXRESULT ijGetHuffmanFREQ_444_DC(const Ipp16s **ppMCUBuf, 
                                int **ppFreq,
                                int ah,
                                int al,
                                IJENCODESTATE *pEncodeState)
{
    if (0!=ah) {
        return IJX_RTCODE_OK;
    }

    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[0],
                                            ppFreq[0],
                                            &(pEncodeState->dcPred[0]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[1],
                                            ppFreq[1],
                                            &(pEncodeState->dcPred[1]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[2],
                                            ppFreq[1],
                                            &(pEncodeState->dcPred[2]),
                                            al);

//    pEncodeState->counter.nScanMCUCounter++;

    if ( (0<pEncodeState->nRstInterval) ){
        pEncodeState->counter.nDRICounter--;
        if (0==pEncodeState->counter.nDRICounter) {
            pEncodeState->counter.nDRICounter=pEncodeState->nRstInterval;
            pEncodeState->dcPred[0]=0;
            pEncodeState->dcPred[1]=0;
            pEncodeState->dcPred[2]=0;
        }
    }

    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijGetHuffmanFREQ_422_DC
// Description:     Get Huffman Frequency for progressive mode
// Input Arguments:
//              ah: Indicates approximation high
//              al: Indicates approximation low
//          ppFreq: Points to the frequency buffer array.
//    pEncodeState: Identifies IJENCODESTATE strcuture.
// Output Arguments:
//        ppMCUBuf: Identifies MCU coefficients buffer.
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_INSUFFICIENTBUF
//                  IJX_RTCODE_ERRPARSE
//                     
******************************************************************************/
IJXRESULT ijGetHuffmanFREQ_422_DC(const Ipp16s **ppMCUBuf, 
                                int **ppFreq,
                                int ah,
                                int al,
                                IJENCODESTATE *pEncodeState)
{
    if (0!=ah) {
        return IJX_RTCODE_OK;
    }

    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[0],
                                            ppFreq[0],
                                            &(pEncodeState->dcPred[0]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(&(ppMCUBuf[0][64]),
                                            ppFreq[0],
                                            &(pEncodeState->dcPred[0]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[1],
                                            ppFreq[1],
                                            &(pEncodeState->dcPred[1]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[2],
                                            ppFreq[1],
                                            &(pEncodeState->dcPred[2]),
                                            al);

//    pEncodeState->counter.nScanMCUCounter++;

    if ( (0<pEncodeState->nRstInterval) ){
        pEncodeState->counter.nDRICounter--;
        if (0==pEncodeState->counter.nDRICounter) {
            pEncodeState->counter.nDRICounter=pEncodeState->nRstInterval;
            pEncodeState->dcPred[0]=0;
            pEncodeState->dcPred[1]=0;
            pEncodeState->dcPred[2]=0;
        }
    }
    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijGetHuffmanFREQ_411_DC
// Description:     Get Huffman Frequency for progressive mode
// Input Arguments:
//              ah: Indicates approximation high
//              al: Indicates approximation low
//          ppFreq: Points to the frequency buffer array.
//    pEncodeState: Identifies IJENCODESTATE strcuture.
// Output Arguments:
//        ppMCUBuf: Identifies MCU coefficients buffer.
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_INSUFFICIENTBUF
//                  IJX_RTCODE_ERRPARSE
//                     
******************************************************************************/
IJXRESULT ijGetHuffmanFREQ_411_DC(const Ipp16s **ppMCUBuf, 
                                int **ppFreq,
                                int ah,
                                int al,
                                IJENCODESTATE *pEncodeState)
{
    if (0!=ah) {
        return IJX_RTCODE_OK;
    }

    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[0],
                                            ppFreq[0],
                                            &(pEncodeState->dcPred[0]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(&(ppMCUBuf[0][64]),
                                            ppFreq[0],
                                            &(pEncodeState->dcPred[0]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(&(ppMCUBuf[0][128]),
                                            ppFreq[0],
                                            &(pEncodeState->dcPred[0]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(&(ppMCUBuf[0][192]),
                                            ppFreq[0],
                                            &(pEncodeState->dcPred[0]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[1],
                                            ppFreq[1],
                                            &(pEncodeState->dcPred[1]),
                                            al);
    ippiGetHuffmanFREQ_JPEG_DCFirst_16s(ppMCUBuf[2],
                                            ppFreq[1],
                                            &(pEncodeState->dcPred[2]),
                                            al);

//    pEncodeState->counter.nScanMCUCounter++;

    if ( (0<pEncodeState->nRstInterval) ){
        pEncodeState->counter.nDRICounter--;
        if (0==pEncodeState->counter.nDRICounter) {
            pEncodeState->counter.nDRICounter=pEncodeState->nRstInterval;
            pEncodeState->dcPred[0]=0;
            pEncodeState->dcPred[1]=0;
            pEncodeState->dcPred[2]=0;
        }
    }
    return IJX_RTCODE_OK;
}

#endif
/* EOF */
